import {findTagById} from '~/server/database/repositories/tag'
export default defineEventHandler(async(e)=>{
  const id = e.context.params?.id ? parseInt(e.context.params.id) : undefined
  if (!id)
    return sendError(e, createError({ statusCode: 400, statusMessage: '参数错误' }))
  try {
    const tag = await findTagById(id)
    if (!tag)
      return sendError(e, createError({ statusCode: 404, statusMessage: '无法找到标签' }))

    return { resource: tag }
  }
  catch (error) {
    return sendError(e, createError({ statusCode: 500, statusMessage: '服务器错误' }))
  }
})